// const { TickSystem } = require("XrFrame/systems")

// packageB/pages/home/home.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    id: 0,
    list:[],
    tanchuang:false,
    youbian:false,
    yonghu:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id: options.id,
      other_member_id:options.other_member_id
    })
  },
  shouchang1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "state": '1',
      "is_ts": '0'
    }
    wx.request({
      url: app.apiurl + 'api/member/memberScAdd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
      }
    })
  },
  shouchang2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "state": '0',
      "is_ts": '0'
    }
    wx.request({
      url: app.apiurl + 'api/member/memberScAdd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.z_yonghu()
    this.z_3qiyindao()
    this.z_duifang()
    this.z_jilu()
  },
  z_duifang() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/otherMemberInfo?other_member_id=' + _this.data.other_member_id,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          duifang: res.data.data
        })
        if(res.data.data.homeInfo != '' && res.data.data.homeInfo != null && wx.getStorageSync("zhuye_home") != new Date().getDate()){
          _this.setData({
            zhuyetc:true
          })
        }
      }
    })
  },
  z_yonghu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          _this.setData({
            login: true,
            yonghu: res.data.data
          })
          
        } 
      }
    })
  },
  z_jilu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/member/homePreview?home_id=' + _this.data.id + '&other_member_id=' + _this.data.other_member_id,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          list: res.data.data.list
        })
        if(_this.data.other_member_id != ''){
          if(_this.data.other_member_id != _this.data.yonghu.id){
          _this.setData({
            youbian:true
          })
        }
        }
      }
    })
  },
  z_3qiyindao(){
    let _this = this
    if (wx.getStorageSync("3qiyindaoxx") != 'true' && _this.data.other_member_id != '0') {
      _this.setData({
        tanchuang: true,
      })
    }
    if (wx.getStorageSync("3qiyindaoxx1") != 'true' && _this.data.other_member_id == '0') {
      _this.setData({
        tanchuang: true,
      })
    }
  },
  z_close1(){
    let _this = this
    if (_this.data.other_member_id != '0') {
      wx.setStorageSync("3qiyindaoxx", 'true')
    }
    if (_this.data.other_member_id == '0') {
      wx.setStorageSync("3qiyindaoxx1", 'true')
    }
    _this.setData({
      tanchuang: false,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})